﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows;
using Microsoft.Xaml.Behaviors;

namespace DataChangeTools.Behavior
{
    public class ImageZoomBehavior : Behavior<FrameworkElement>
    {
        public static readonly DependencyProperty ZoomAreaProperty =
            DependencyProperty.Register("ZoomArea", typeof(EllipseGeometry), typeof(ImageZoomBehavior), new PropertyMetadata(null));

        public EllipseGeometry ZoomArea
        {
            get { return (EllipseGeometry)GetValue(ZoomAreaProperty); }
            set { SetValue(ZoomAreaProperty, value); }
        }

        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.MouseMove += OnMouseMove;
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            AssociatedObject.MouseMove += OnMouseMove;
        }


        private void OnMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            ZoomArea = new EllipseGeometry(new System.Windows.Point(0, 0), 50, 50);
            if (ZoomArea != null)
            {
                // 获取鼠标位置
                System.Windows.Point position = e.GetPosition(AssociatedObject);
                // 更新圆形区域的位置
                ZoomArea.Center = position;
            }
        }
    }
}
